//引入l7控件
import {
  Fullscreen,
  Zoom,
  MouseLocation,
  MapTheme,
  LayerSwitch,
  Scale,
  //   Logo,
} from "@antv/l7"
export default function useControl(scene, map) {
  // 首先，在函数内部创建了一个空对象sceneControls，用于存储即将创建的各个控件实例。
  //   sceneControls.fullscreen = new Fullscreen({})创建了一个全屏控制（Fullscreen）的实例，并将其存储在sceneControls对象的fullscreen属性下。
  const sceneControls = {}
  sceneControls.fullscreen = new Fullscreen({})
  sceneControls.zoom = new Zoom({
    position: "topleft",
  })
  sceneControls.mouseLocation = new MouseLocation({
    position: "bottomright",
  })
  sceneControls.scale = new Scale({
    position: "bottomright",
  })
  //添加主题切换的控件
  sceneControls.mapTheme = new MapTheme({
    options: [
      {
        text: "白天导航地图",
        value: "mapbox://styles/mapbox/navigation-day-v1",
        img: "/themes/navigation-day-v1.png",
      },
      {
        text: "夜间导航地图",
        value: "mapbox://styles/mapbox/navigation-night-v1",
        img: "/themes/navigation-night-v1.png",
      },
      {
        text: "标记卫星图",
        value: "mapbox://styles/mapbox/satellite-streets-v12",
        img: "/themes/satellite-streets-v12.png",
      },
      {
        text: "普通卫星图",
        value: "mapbox://styles/mapbox/satellite-v9",
        img: "/themes/satellite-v9.png",
      },
    ],
  })
  for (let key in sceneControls) {
    scene.addControl(sceneControls[key])
  }
  sceneControls["scale"].hide()
  map.on("zoom", function () {
    let zoom = map.getZoom()
    if (zoom < 5) {
      sceneControls.scale.hide()
    } else {
      sceneControls.scale.show()
    }
  })
}
